package com.cloud.wms.ui.sort.group;


import android.content.Context;
import android.content.Intent;
import android.os.Message;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloud.widget.ScanText;
import com.cloud.wms.R;
import com.cloud.wms.base.BaseBarActivity;
import com.cloud.wms.config.IntentKey;
import com.cloud.wms.ui.sort.contract.GroupSortContract;
import com.cloud.wms.ui.sort.entity.BindInfoEntity;
import com.cloud.wms.ui.sort.presenter.GroupSortPresenter;

import butterknife.BindView;

/**
 * @Author:Chen
 * @Date: 2021-03-01 16:51
 * @Description: 备货完成跳转的集货
 */
@Deprecated //使用  com.cloud.wms.ui.group.collect.GroupCollectActivity
public class GroupCollectActivity extends BaseBarActivity<GroupSortPresenter> implements GroupSortContract.View {

    @BindView(R.id.scan_text)
    ScanText scanText;
    @BindView(R.id.tv_collect_code)
    TextView tvCollectCode;
    @BindView(R.id.tv_scan_name)
    TextView tvScanName;
    @BindView(R.id.ll_collect_info)
    LinearLayout llCollectInfo;
    private BindInfoEntity bindInfoEntity;

    @Override
    protected String barTitle() {
        return "团购集货";
    }

    @Override
    protected int getResId() {
        return R.layout.activity_sort_group_collection;
    }

    @Override
    protected void initEvent() {
        initScanText(scanText);
        bindInfoEntity = getIntent().getParcelableExtra(IntentKey.INFO_KEY);
        llCollectInfo.setVisibility(View.VISIBLE);
        tvCollectCode.setText(bindInfoEntity.getCollectCode());
        tvScanName.setText("集货地号");
    }

    @Override
    protected void onScanHandle(String result, int resultCode) {
        super.onScanHandle(result, resultCode);
        scanText.addHistory(result);
        if (result.equalsIgnoreCase(bindInfoEntity.getCollectCode()))
            mPresenter.submitCollect(bindInfoEntity.getBillID() + "", result);
        else
            info("集货地扫描验证失败!");
    }

    @Override
    protected void setupComponent() {
        getActivityComponent().inject(this);
    }

    @Override
    public void onSuccess(Message message) {
        switch (message.what) {
            case GroupSortPresenter.SUBMIT_COLLECT:
                success("集货成功！");
                this.finish();
                break;
        }
    }

    public static void start(Context context, BindInfoEntity bindInfoEntity) {
        Intent intent = new Intent(context, GroupCollectActivity.class);
        intent.putExtra(IntentKey.INFO_KEY, bindInfoEntity);
        context.startActivity(intent);
    }
}
